package com.im.project.rabbitmq;

import com.im.common.constant.Constant;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rabbitmq配置初始化
 *
 * @author yunZhouJiaDi
 */
@Configuration
public class RabbitmqInit {

    @Bean(Constant.RabbitmqConstant.EXCHANGE_MESSAGE)
    public Exchange exchange() {
        return ExchangeBuilder.topicExchange(Constant.RabbitmqConstant.EXCHANGE_MESSAGE).durable(true).build();
    }

    @Bean(Constant.RabbitmqConstant.QUEUE_SYS_MESSAGE)
    public Queue queue() {
        return new Queue(Constant.RabbitmqConstant.QUEUE_SYS_MESSAGE);
    }

    @Bean
    public Binding binding(@Qualifier(Constant.RabbitmqConstant.EXCHANGE_MESSAGE) Exchange exchange,
                           @Qualifier(Constant.RabbitmqConstant.QUEUE_SYS_MESSAGE) Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with(Constant.RabbitmqConstant.ROUTING_KEY).noargs();
    }

}
